package edu.upc.fib.lamsandroid.client.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import edu.upc.fib.lamsandroid.client.view.ScaleImageView;

import java.net.MalformedURLException;
import java.net.URL;

public class ImageDialog {

    private final Context context;
    private final String url;

    public ImageDialog(Context contextAndListener, String url) {
        this.context = contextAndListener;
        this.url = url;
    }

    public void show() {
        try {
            AlertDialog ad = new AlertDialog.Builder(context).create();
            ad.setCancelable(false);

            ScaleImageView scaleImageView = new ScaleImageView(context);
            scaleImageView.setImageURL(new URL(url));
            ad.setView(scaleImageView);

            ad.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            ad.show();
        } catch (MalformedURLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
